<template>
	<view>
		<cu-custom class="text-Black" bgColor="bg-red" :isBack="true">
			<block slot="backText"></block>
			<block slot="content">设置</block>
		</cu-custom>
		<view class="cu-list menu margin-top">
			<view class="cu-item arrow" @tap="goPage('/pages/member/edit')">
				<view class="content">个人信息</view>
			</view>
			<view class="cu-item arrow" @tap="goPage('/pages/member/password')">
				<view class="content">修改密码</view>
			</view>
			<view class="cu-item arrow" @tap="goPage('/pages/member/password2')">
				<view class="content">修改支付密码</view>
			</view>
		</view>
		<view class="cu-list menu margin-top">
			<!-- <view class="cu-item arrow" @tap="goPage('/pages/member/oauth/index')">
				<view class="content">授权管理</view>
			</view> -->
			<view class="cu-item arrow" @tap="goPage('/pages/member/address/list')">
				<view class="content">收货地址</view>
			</view>
			<view class="cu-item arrow" @tap="clearCache">
				<view class="content">清除缓存</view>
				<view class="action">{{cache_size}}kb</view>
			</view>
		</view>
		<view class="cu-list menu margin-top">
			<view class="cu-item arrow" @tap="goPage('/pages/site/about')">
				<view class="content">关于我们</view>
			</view>
			<view class="cu-item arrow" @tap="goPage('/pages/site/feedback')">
				<view class="content">意见反馈</view>
			</view>
		</view>
		<!-- <view class="cu-list menu margin-top">
			<view class="cu-item arrow">
				<view class="content">主题<text class="cuIcon-colorlens" :class="'text-'+theme"></text></view>
				<view class="action">
					<view class="cu-btn round" :class="'bg-'+theme" @tap="modalName='colorModal'">选择主题</view>
				</view>
			</view>
		</view> -->

		<view class="margin">
			<view class="cu-btn lg w100" :class="'line-'+theme" @click="onExit">退出登录</view>
		</view>


		<view class="cu-modal bottom-modal" :class="modalName=='colorModal'?'show':''" @tap="modalName=''">
			<view class="cu-dialog" @tap.stop=''>
				<view class="padding-xl">
					<view class="grid col-4">
						<view class="padding-sm" v-for="(item,index) in colorList" v-if="index<14" :key="index">
							<view class="cu-btn shadow-blur round" :class="'bg-'+item.name" @tap="selectTheme(item)">
								{{item.title}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		components: {},
		data() {
			return {
				cache_size: 0,
				modalName: '',
				theme: this.$config.THEME(),
				colorList: []
			}
		},
		onLoad(options) {
			if (this.$common.loginAuth(true)) {
				this.mathCacheSize()
				this.colorList = this.ColorList
				console.log(this.ColorList)
			}
		},
		methods: {
			...mapMutations(['logout', 'info']),
			mathCacheSize() {
				let app_data = uni.getStorageSync('app_data')
				this.cache_size = parseInt(JSON.stringify(app_data).length / 1024)
			},
			clearCache() {
				let _this = this
				uni.showModal({
					title: '系统提示',
					content: '是否确定清除缓存',
					success(res) {
						if (res.confirm) {
							uni.setStorageSync('app_data', '')
							_this.mathCacheSize()
							_this.$common.showSuccess('操作成功')
						} else if (res.cancel) {

						}
					}
				})
			},
			onExit() {
				this.logout()
				uni.clearStorageSync()
				// let promise = this.$tim.tim.logout()
				// if (promise) {
				// 	promise.then(function(imResponse) {
				// 		this.$store.commit('timLogout')
				// 		console.log(imResponse.data); // 登出成功
				// 	}).catch(function(imError) {
				// 		console.warn('logout error:', imError);
				// 	});
				// }

				this.$common.showSuccess('退出成功', (r) => {
					uni.redirectTo({
						url: '/pages/site/login'
					})
				})
			},
			selectTheme(item) {
				uni.setStorageSync('theme', item.name)
				this.theme = this.$config.THEME()
				this.modalName = ''
			}
		},
	}
</script>

<style>
</style>
